#include "StdAfx.h"
#include "VocoderDriver.h"
#include "../Vocoder/Vocoder.h"
#include "../Vocoder/Settings.h"

VocoderDriver::VocoderDriver(void)
{
}

VocoderDriver::~VocoderDriver(void)
{
}

void VocoderDriver::Initialize(Settings* settings, Modulator* modulator, Carrier* carrier, Vocoder* vocoder, int windowLength)
{
	this->settings = settings;
	this->modulator = modulator;
	this->carrier = carrier;
	this->vocoder = vocoder;
	this->windowLength = windowLength;
	modulatorOutput.resize(windowLength, 0);
	carrierOutput.resize(windowLength, 0);
	vocoderOutput.resize(windowLength);
}

void VocoderDriver::Start()
{
	vocoding = true;
	while(vocoding)
	{
		std::vector<SampleMarker> markers;
		vocoding = modulator->NextModulatorSample(&modulatorOutput[0], windowLength, &markers);		
		short* carrierSample = carrier->CreateCarrierSample(settings, &modulatorOutput[0], windowLength, &markers);
		vocoder->Vocode(&modulatorOutput[0], carrierSample, &vocoderOutput[0], windowLength);
	}
}

void VocoderDriver::Stop()
{
	vocoding = false;
}
